package com.mrwang.controller;

import com.mrwang.PageResult;
import com.mrwang.pojo.GoodsEs;
import com.mrwang.pojo.SearchRequest;
import com.mrwang.service.SearchService;
import jdk.nashorn.internal.ir.IfNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SearchController {
    @Autowired
    SearchService searchService;

    @PostMapping("page")
    public ResponseEntity<PageResult<GoodsEs>> search(@RequestBody SearchRequest searchRequest){
        PageResult<GoodsEs> page= searchService.search(searchRequest);
        if (page==null){
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
        return ResponseEntity.ok(page);
    }
}
